Skip to content

Add optional support for prebuilt binaries#86

Open
FrankenApps wants to merge 3 commits into
GregoryConrad:mainfrom
FrankenApps:prebuilt-binaries
Open

Add optional support for prebuilt binaries#86
FrankenApps wants to merge 3 commits into
GregoryConrad:mainfrom
FrankenApps:prebuilt-binaries

Conversation

@FrankenApps

Copy link
Copy Markdown

This is an attempt to add support for prebuilt binaries that are downloaded from a remote server instead of building from source on an opt-in basis.

Reasoning

This feature is useful if downstream users want to avoid installing rustup or if they want to avoid building from source due to constrained disk space.

Additionally this also allows building in air-gapped environments without internet access, if the prebuilt binaries are served via a local server.

Design

The feature is roughly modeled after the support for precompiled binaries in cargokit.

At build-time the hook will check if there is a native_toolchain_rust.toml file in the root folder of the downstream application (or Dart workspace) using a native_toolchain_rust based library.

I have a (hopefully self-explanatory) example below that can also be used for testing:

[prebuilt-binaries.dart_only_prebuilt_binaries_example]
url = "https://github.com/FrankenApps/native_toolchain_rust/releases/download/dart_only_prebuilt_binaries_example-v{version}/dart_only_prebuilt_binaries_example-{target}.bin"

Note that (I think contrary to the implementation in Cargokit) the build will fail if a config file is present that for example points to an invalid URL. I found that to be more transparent for the user instead of (silently) falling back to building from source (I expect most users to not specify a custom logger).

Safety

The feature is completely opt-in and I still advised users to rely on building from source whenever possible, but as mentioned above there are circumstances where this is rather undesirable.

I contemplated letting users optionally specify a list of SHA256 hashes of which every downloaded binary per target must match exactly one, for improved safety, but for now decided against it, because it would be tedious for the users having to manually add them for every new version.

Testing

I added new tests and a dedicated example. I also updated the documented with a high-level explanation of the feature.

Please let me know what you think.

@GregoryConrad

Copy link
Copy Markdown
Owner

Hey! Thanks for opening the PR.

I’m not really convinced yet that pre-built binaries are a good idea (my stance on them has changed a bit over time). The first two points (not wanting to install rustup/disk-space feel easily fixable to me), but the third warrants a conversation:

Additionally this also allows building in air-gapped environments without internet access, if the prebuilt binaries are served via a local server.

Why not just pre-cache all deps you need in advance/ship them to the air-gapped environment? If that requires some support in this library, then that’s definitely something I’d be willing to support here.

@FrankenApps

FrankenApps commented Jun 19, 2026

Copy link
Copy Markdown
Author

I fully agree with you. I don't think prebuilt binaries should be used either, as they pose a major supply chain risk. That's why the feature is fully optional, non-intrusive, and must be explicitly opted into by the user. I'd also encourage users to always build from source and if they don't, at least to build and host the prebuilt binaries themselves (if you'd like me to point this out more clearly in the README, I could easily do that).

Why not just pre-cache all deps you need in advance/ship them to the air-gapped environment?

Sure, that's possible. Yet the correct toolchain will need to be installed through rustup, which likely requires Internet access nevertheless. I am not saying that it's impossible to work around this—it certainly isn't—but it does make working with libraries that use native_toolchain_rust more of a hassle.

not wanting to install rustup/disk-space feel easily fixable to me

Would you mind explaining what you have in mind for fixing this another way? I honestly have some doubts about whether that's possible, especially regarding the disk space issue. It is not only the build/ directory that becomes quite large quite quickly, but also the cargo cache. Yet I don't see how this could be cleaned up, because if it were, then even incremental rebuilds would take a really long time.

The disk space issue was also mentioned in the original issue that brought me here.

I just realized that I forgot to mention the main reason why I would like to have this feature. A full rebuild after a flutter clean takes a very long time to complete on my machine (10+ minutes for rhttp) and consistently causes my machine to run out of memory after building 2 out of the 3 Android targets.

For these reasons, I thought that this feature might be useful for other users, and I was hoping it would be well received.

I also felt that the implementation was quite simple and straightforward, but of course I'll defer to your judgment on whether it belongs in the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants